-
Notifications
You must be signed in to change notification settings - Fork 89
fix: copy public directory output instead of input when using Nx #856
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
src/index.js
Outdated
@@ -47,14 +47,14 @@ module.exports = { | |||
|
|||
checkNextSiteHasBuilt({ publish, failBuild }) | |||
|
|||
const { appDir, basePath, i18n, images, target, ignore } = await getNextConfig({ publish, failBuild }) | |||
const { appDir, basePath, i18n, images, target, ignore, outdir } = await getNextConfig({ publish, failBuild }) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can you explain where you're getting this config name? I'm not aware of outdir
being a standard config value.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It's added when you're using Next.js with Nx. You can see the source code adding it here
The |
Ah, looks like this is a difference when using Next with Nx. Nx copies the public directory over to the specified output directory, where it also puts the The issue with putting generated files in the generated Would you support updating the PR to conditionally use/join |
I went ahead and made it conditional with a comment explaining the case. I also made a Nx workspace with a Next.js project to demonstrate -- https://github.com/lourd/nx-next-public-example. To see what I'm talking about, clone it and run If you want, you can also run the build to see the service worker getting registered and loaded from that public location. The command for that is |
I also just added a test to the Cypress suite for |
🔨 Explore the source changes: 49c5147 |
|
||
it('serves generated public files', () => { | ||
cy.request(`service-worker.js`) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You can be more explicit with the assetion here by making sure the status returned is a 200. Something like this:
cy.request(`service-worker.js`) | |
cy.request('service-worker.js').then((res) => { | |
expect(res.status).to.eq(200) | |
}) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
👍 went ahead and added that and a check for the content-type (in case it's serving some fallback html instead of js!)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thank you for the test steps, comments and taking the time to explain the nx use case, super appreciated! I tested using your test steps with and without the outdir as well as using netlify deploy --build
and things seem to be behaving as expected 🎉 .
😃 For sure! Please let me know if there's anything else this needs to be merged. |
This PR currently has a merge conflict. Please resolve this and then re-add the |
Summary
When copying the
public
directory, the build plugin should use the one that Next.js generates as part of the build, not the input one, as there may be files added to the directory as part of the build process. For example, using theInjectManifest
plugin fromworkbox-webpack-plugin
like this to produce the specifically named and located fileservice-worker.js
:Test plan
Added a test to the Nx cypress setup. Steps to run:
cd demos/nx-next-monorepo-demo npm install npm run build npx nx run demo-monorepo:serve:production --port=3000
Then in a separate terminal, from the repo root
Then click the
general.spec.ts.
under thenx
folder to run it.Relevant links (GitHub issues, Notion docs, etc.) or a picture of cute animal
Standard checks: